package com.tyq.lianxi_1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class Simple_Activity extends AppCompatActivity {

	private ListView lv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_simple_);
		init();
	}

	private void init() {
		lv = (ListView) findViewById(R.id.simple_listView1);
		List<Map<String, Object>> datas = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < 15; i++) {
			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("name", "abc"+i);
			map1.put("image", R.drawable.ic_launcher);
			datas.add(map1);
		}
		SimpleAdapter adapter = new SimpleAdapter(this, datas, R.layout.item_1,
				new String[]{"name", "image"}, new int[]{R.id.item_1_textView1, R.id.item_1_imageView1});
		lv.setAdapter(adapter);
		listener();
	}

	private void listener() {
		lv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				TextView tv = (TextView) arg1.findViewById(R.id.item_1_textView1);
				Toast.makeText(Simple_Activity.this, tv.getText(), Toast.LENGTH_SHORT).show();
			}
		});
	}
}
